import React, { Component } from 'react';
import { createPortal } from 'react-dom';
import ReactEcharts from 'echarts-for-react';
import darkEchartsTheme from '../../config/theme/darkEchartsTheme';
import echarts from 'echarts';

const modalRoot = document.getElementById('dialog-root');

class IndustrymapDevelopNumBottomChart extends Component {
  constructor(props) {
    super(props);
    this.el = document.createElement('WorldCsjGdpBarChart');
    this.state = {
      chartOption: undefined,
      chartHeight: 270,
    };
  }
  componentDidMount() {
    modalRoot.appendChild(this.el);
    echarts.registerTheme('theme_name', darkEchartsTheme);
    this.setChartData();
  }

  setChartData() {
    const option = {
      tooltip: {
        show: true,
        trigger: 'item',
        formatter: '{b} : {c}',
      },
      grid: {
        top: '5%',
        left: '0%',
        right: '3%',
        bottom: '6%',
        containLabel: true,
      },
      legend: {
        icon: 'rect',
        data: ['国家级开发区','省级开发区'],
        textStyle: {
          fontWeight: 'normal',
          fontSize: 12,
          color: "#fff",
        }
      },
      xAxis: {
        data: ['上海', '江苏', '浙江', '安徽'],
        axisLine: {
          lineStyle: {
            // color: '#0177d4'
          }
        },
        splitLine: {
          show: false,

        },
        axisLabel: {
          color: '#fff',
          interval: 0,
          fontSize: 11,
        }
      },
      yAxis: {
        name: "",
        nameTextStyle: {
          color: '#fff',
          fontSize: 12
        },
        axisLine: {
          lineStyle: {
            // color: '#0177d4'
          }
        },
        axisLabel: {
          color: '#fff',
          fontSize: 10,
        },
        splitLine: {
          show: false,
          lineStyle: {
            color: '#0177d4'
          }
        },
        max: 120

      },
      series: [{
        name:'国家级开发区',
        type: 'bar',
        barWidth: 10,
        barGap: '100%',
        barCategoryGap: '100%',
        itemStyle: {
          normal: {
            barBorderRadius: 18,
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 1,
                color: '#0286ff',
              },
              {
                offset: 0.5,
                color: '#027eff',
              },
              {
                offset: 0,
                color: '#00feff',
              },
            ]),
          }
        },
        data: [6, 26, 21, 12]
      }, {
        name:'省级开发区',
        type: 'bar',
        barWidth: 10,
        barGap: '100%',
        barCategoryGap: '100%',
        itemStyle: {
          normal: {
            barBorderRadius: 18,
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
              offset: 0,
              color: '#f6e3a1'
            }, {
              offset: 1,
              color: '#ff4236'
            }]),
          }
        },
        data: [39, 103, 82, 96]
      }]
    };
    this.setState({ chartOption: option });
  }

  render() {
    const { style, width, height } = this.props;
    const dtTitle = `开发区数量`;
    const { chartOption } = this.state;
    return createPortal(
      <div
        style={{
          ...style,
          display: 'flex',
          flexDirection: 'column',
          width: width,
          height: height,
          color: '#fff',
          backgroundColor: 'rgba(0,0,0,0.6)',
          boxShadow: '0 1px 2px rgba(0,0,0,0.16), 0 1px 2px rgba(0,0,0,0.23)',
        }}
      >
        <div
          style={{
            lineHeight: '35px',
            height: 35,
            borderBottom: '1px solid rgb(238, 238, 238,0.2)',
            textAlign: 'center',
            fontWeight: 'bold'
          }}
        >
          <div style={{ float: 'left', marginLeft: 6, fontSize: 15 }}><div style={{ float: 'left', width: 5, height: 35, marginRight: 10, backgroundColor: 'rgba(63,177,277,1)', }} />{dtTitle}</div>
          <div style={{ float: 'right', marginRight: 8 }}>
          </div>
        </div>
        <div style={{ margin: '3px 3px 3px 3px' }}>
          <div>
            {chartOption !== undefined && (
              <ReactEcharts
                option={chartOption}
                notMerge={true}
                lazyUpdate={true}
                theme={'theme_name'}
                style={{ height: this.state.chartHeight }}
              />
            )}
          </div>
        </div>
      </div>,
      this.el
    );
  }
}

export default IndustrymapDevelopNumBottomChart;
